<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/course_php.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
	$con = @mysql_connect('localhost', 'root', '');
	if (!$con) {
		die("Đã xảy ra lỗi trong quá trình xử lý." . mysql_error());
	}
	
	$db_selected = @mysql_select_db('studial');
	if (!$db_selected) {
		die("Đã xảy ra lỗi trong quá trình xử lý." . mysql_error());
	}
?>
<title><?php ?></title>
<link rel="stylesheet" type="text/css" href="../css/global.css" />
<link rel="stylesheet" type="text/css" href="../css/loggedpages.css" />
<!-- InstanceBeginEditable name="head" -->
<style type="text/css">
	#eventtable {
		width: 580px;
		margin: 2em auto 2em auto;
		border-width: 0;
	}
	
	#eventtable td {
		width: inherit;
		border-top: 1pt solid #d0d0d0;
		padding: 20px 10px 20px 10px;
		font-size: 13px;
	}
	
	td#headrow {
		border-top-width: 0;
		padding: 0 0 10px 0;	
	}
	
	.greenbutton { 
		width: 110px; 
		margin-top: 0;
		padding-right: 15px;
	}
	
	.eventinfo {
		float: left;
		width: 420px;	
	}
	
	.eventname {
		font-size: 14px;
		font-weight: 700;
		margin-bottom: 0.3em;	
	}
	
	.eventdesc { color: #888888; }
	
	.eventact {
		float: right;
		text-align: right;
		width: 120px;	
	}
</style>
<!-- InstanceEndEditable -->
</head>

<body>
	<div class="header">
        <div class="innercontent">
            <img alt="Studial" class="logo" src="../images/logo.jpg" />   
            <form id="searchform" method="post" action="">
                <div id="searchblock">
                    <input id="searchfield" name="searchfield" type="text" placeholder="Tìm kiếm" />
                    <button id="searchbutton" type="submit" name="search" value="1" title="Tìm kiếm" onclick="window.location = '../unlogged/index.php'"><img id="searchicon" src="../images/searchicon.png" /></button>
                </div>           
            </form>
            <div id="rightheader">
                <a class="headerbutton" id="logout"><span id="borderleft"></span>Đăng xuất</a>
                <a class="headerbutton" id="toboard"><?php echo "Username" ?></a>
            </div>
        </div>
    </div>
    <div class="innercontent">
        <div id="leftcolumn">
            <img alt="Avatar" id="largeavatar" src="<?php echo $path = "../images/male_avatar.png"; ?>" />
        	<div id="sidenavcontainer">	
                <ul id="sidenav">
            		<li><a class="navlink" href=""><span id="boardnav">Bảng</span></a></li>
                    <li><a class="navlink" href=""><span id="eventnav">Sự kiện</span></a></li>
                    <li><a class="navlink" href=""><span id="membernav">Thành viên</span></a></li>
                    <?php if (1) echo "<li><a class=\"navlink\" href=\"\"><span id=\"gradenav\">Bảng điểm</span></a></li>"; ?>
            	</ul>
            </div>
        </div>
        <div id="contentcolumn">
        	<div id="contentcolheader">
            	<h2>Coursename</h2>
                <div id="description">Description</div>
            </div>
		<!-- InstanceBeginEditable name="maincontent" -->
        <table id="eventtable">
        <tr>
			<td id="headrow"><a href="../createEvent.php"><button class="greenbutton">+ Tạo sự kiện</button></a></td>
 		</tr>
		<?php
			function returndatetime($id)
			{
				$date = new DateTime($id);
				return $date->format('d/m/Y');			
			}
			function getdatetimesubmit($assignmentid, $user_id)
			{
				$result = mysql_query("select * from `assignment_submission` where `assignment_id` = '".$assignmentid."' and `user_id` = '".$user_id."';");
				$row = mysql_fetch_array($result);
				return $row['datesubmitted'];	
			}
			function issubmitted($assignmentid, $user_id)
			{
				$result = mysql_query("select * from `assignment_submission` where `assignment_id` = '".$assignmentid."' and `user_id` = '".$user_id."';");
				$row_num = mysql_num_rows($result);
				return $row_num;
			}
			//----------------------------------------------------
			$course_id = $_GET['id'];
			$user_id = $_COOKIE['studialuserid'];
			
			//Tim course
			$result1 = mysql_query("select * from `assignments` where `course_id` = '".$course_id."';");
			$rows1_num = mysql_num_rows($result1);
			
			//Tim tat ca bai da nop cua user dang dung
			$result2 = mysql_query("select * from `assignment_submission` where `assignment_id` = '".$course_id."' and `user_id` = '".$user_id."';");
			$rows2_num = mysql_num_rows($result2);
			
		
			for( $j = 0 ; $j < $rows1_num ; $j ++)
			{
				$rows = mysql_fetch_array($result1);
				echo '<tr>';
				echo '<td>';
				echo '<div class="eventinfo">';
				echo '<div class="eventname"><a href="../viewEvent.php?id=">'.stripslashes($rows['name']).'</a></div>';
				echo '<div class="eventdesc">Hạn nộp: '.returndatetime($rows['finishdate']).'</div>';	
				if(issubmitted($rows['id'],$user_id)!=0)
				{
					$date = returndatetime(getdatetimesubmit($rows['id'],$user_id));
					echo '<div class="eventstate">Đã nộp bài lúc '.$date.'</div>';
				}
				else
				{
					echo '<div class="eventstate">Chưa nộp bài</div>';
				}
			}
		
		?>
        </table>
		<!-- InstanceEndEditable -->
    	</div>
    </div>
    <div class="footer">
    	<div id="leftfooter">Studial @ 2012 - Nhóm 01</div>
        <div id="rightfooter">
			<a href="" title="Đăng ký thêm tên trường vào hệ thống">Đăng ký trường</a>
            -
            <a href="" title="Đăng ký thêm tên ngành học vào hệ thống">Đăng ký ngành</a>
        </div>
    </div>       
</body>
<!-- InstanceEnd --></html>
